home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / reuse.lha / reuse / c / SetsDrv.c < prev    next >
Text File  |  1992-08-18  |  3KB  |  106 lines

  1. /* $Id: SetsDrv.c,v 1.6 1992/05/05 13:19:05 grosch rel $ */
  2.  
  3. /* $Log: SetsDrv.c,v $
  4.  * Revision 1.6  1992/05/05  13:19:05  grosch
  5.  * added rcsid
  6.  *
  7.  * Revision 1.5  1991/11/21  14:28:16  grosch
  8.  * new version of RCS on SPARC
  9.  *
  10.  * Revision 1.4  90/09/20  09:12:27  grosch
  11.  * calmed down lint
  12.  * 
  13.  * Revision 1.3  90/07/04  14:34:06  grosch
  14.  * introduced conditional include
  15.  * 
  16.  * Revision 1.2  89/12/08  17:25:04  grosch
  17.  * complete redesign in order to increase efficiency
  18.  * 
  19.  * Revision 1.1  89/01/09  17:29:45  grosch
  20.  * added functions Size, Minimum, and Maximum
  21.  * 
  22.  * Revision 1.0  88/10/04  11:44:46  grosch
  23.  * Initial revision
  24.  * 
  25.  */
  26.  
  27. /* Ich, Doktor Josef Grosch, Informatiker, Sept. 1987 */
  28.  
  29. static char rcsid [] = "$Id: SetsDrv.c,v 1.6 1992/05/05 13:19:05 grosch rel $";
  30.  
  31. # include "ratc.h"
  32. # include <stdio.h>
  33. # include "Sets.h"
  34.  
  35. # define max        1000
  36.  
  37. static    tSet        s, t, u    ;
  38. static    int        i    ;
  39. static    FILE *        f    ;
  40.  
  41. main ()
  42. {
  43.    MakeSet (& s, max);
  44.    MakeSet (& t, max);
  45.    MakeSet (& u, max);
  46.  
  47.    for (i = 2; i <= max; i ++) { Include (& t, i); }
  48.  
  49.    AssignEmpty (& s);
  50.    AssignElmt (& s, 1);
  51.    Assign (& u, & t);
  52.    Union (& s, & t);
  53.  
  54.    AssignEmpty (& t);
  55.    for (i = 0; i <= max; i += 2) { Include (& t, i); }
  56.    Difference (& s, & t);
  57.  
  58.    for (i = 0; i <= max; i += 3 ) { Exclude (& s, i); }
  59.    for (i = 0; i <= max; i += 5 ) { Exclude (& s, i); }
  60.    for (i = 0; i <= max; i += 7 ) { Exclude (& s, i); }
  61.    for (i = 0; i <= max; i += 11) { Exclude (& s, i); }
  62.    for (i = 0; i <= max; i += 13) { Exclude (& s, i); }
  63.    for (i = 0; i <= max; i += 17) { Exclude (& s, i); }
  64.    for (i = 0; i <= max; i += 19) { Exclude (& s, i); }
  65.    for (i = 0; i <= max; i += 23) { Exclude (& s, i); }
  66.    for (i = 0; i <= max; i += 29) { Exclude (& s, i); }
  67.  
  68.    f = fopen ("/tmp/t", "w");
  69.    WriteSet (f, & s);
  70.    (void) fprintf (f, "\n");
  71.    (void) fclose (f);
  72.  
  73.    f = fopen ("/tmp/t", "r");
  74.    ReadSet (f, & t);
  75.    (void) fclose (f);
  76.  
  77.    WriteSet (stdout, & t);
  78.    (void) printf ("\n%5d%5d%5d\n", Size (& t), Minimum (& t), Maximum (& t));
  79.    ReleaseSet (& s);
  80.    ReleaseSet (& t);
  81.    ReleaseSet (& u);
  82.  
  83.    MakeSet    (& s, 10);
  84.    Include    (& s, 3);
  85.    Include    (& s, 7);
  86.    (void) printf ("\nenter Size and Set like below! (Size=0 terminates)\n10 ");
  87.    WriteSet    (stdout, & s);
  88.    (void) printf ("\n");
  89.    ReleaseSet    (& s);
  90.  
  91.    for (;;) {
  92.       (void) printf ("\n");
  93.       (void) scanf ("%d", & i);
  94.       if (i == 0) break;
  95.       MakeSet    (& s, i);
  96.       ReadSet    (stdin, & s);
  97.       WriteSet    (stdout, & s);
  98.       (void) printf (" Card = %d\n", Card (& s));
  99.       Complement(& s);
  100.       WriteSet    (stdout, & s);
  101.       (void) printf (" Card = %d\n", Card (& s));
  102.       ReleaseSet(& s);
  103.    }
  104.    return 0;
  105. }
  106.